Skip to content

fix(id/web): validate identity endpoint responses before persisting (#7839) - #8505

Merged
dezren39 merged 2 commits into
mainfrom
queue/14019-7839-identity-response-validation
Nov 11, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/14019-7839-identity-response-validation

Conversation

@dezren39

@dezren39 dezren39 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Fixes #7839 (task 14019).

What

pkgs/id/web/src/main.ts trusted the shape of all three identity endpoint responses: data.token / data.client_id / data.name flowed from an unguarded resp.json() into saveIdentity, which String()-coerces into localStorage — a wrong-shape 200 persisted a fake 'undefined' / '[object Object]' identity, and a wrong-shape /me 200 overwrote a valid stored token.

Change

  • src/identity-refresh.ts (home of identityNeedsRefresh, pattern: parseUploadResponse for id(web/image-upload): /api/upload response shape-trusted — a wrong-shape 200 inserts an image node with src undefined into the document #7823): adds parseIdentityMeResponse, parseIdentityRegisterResponse, parseIdentityNameResponse. Plain-object body required; token/client_id non-empty strings when required (register) or present (/me rotation); name string-or-null. Anything else throws.
  • src/main.ts: all three fetch sites parse through the validators, so a wrong-shape body fails through the existing error paths — register returns null without calling saveIdentity; /me falls back to the stored identity untouched; /name returns null without calling updateStoredName.

Tests

  • New regression tests in src/identity-refresh.test.ts cover {}, null, bare string, array, numeric token, object token/client_id, empty token, and non-string name for register and /me, plus non-string/missing name for /name (oracle: the parser throws, which is what keeps localStorage unchanged). Targeted file: 15/15 pass.
  • Typecheck (tsc --noEmit) clean.
  • Full pkgs/id web suite: 720 passed; 1 pre-existing failure (search-panel.test.ts role=search aria-label — verified failing identically on clean main) and 1 flake (tags.test.ts, passes in isolation on both clean main and this branch).

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 11, 2026 03:51
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T03:58:52.724570Z 1f01c77 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 48 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 16944c86-a595-4ea7-a68b-3bff7f941340
Commits

Reviewing files that changed from the base of the PR and between 786ee93 and 1f01c77.

Files selected for processing: 3

  • pkgs/id/web/src/identity-refresh.test.ts
  • pkgs/id/web/src/identity-refresh.ts
  • pkgs/id/web/src/main.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c26fce350d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +48 to +50
describe("parseIdentityRegisterResponse (#7839)", () => {
it("accepts a well-shaped registration", () => {
expect(parseIdentityRegisterResponse({ token: "tok", client_id: "cid", name: "Ada" })).toEqual({

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Cover identity response invariants with property tests

The three new response parsers have meaningful validation invariants, but their tests exercise only fixed examples. Root AGENTS.md explicitly requires property-based coverage for parsers and says example-based tests do not replace it. Add generated JSON inputs with an independent acceptance predicate, checking that invalid shapes throw and valid fields are preserved without coercion; retain these examples as regression cases.

AGENTS.md reference: AGENTS.md:L41-L45

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1f01c77 — property coverage added for all three parsers (seeded generator, 2000 generated inputs per parser, independent acceptance predicates as oracle, no-coercion assertions on accepted inputs). Full detail: #8505 (comment)

@dezren39

Copy link
Copy Markdown
Member Author

Fixed in 1f01c77: added property coverage for all three parsers in identity-refresh.test.ts — a seeded generator (mulberry32, failures reproduce from the seed) builds random JSON-shaped payloads (random field subsets across token/client_id/name/extra, random value types including numeric/object/array scalars), 2,000 inputs per parser, checked against independent acceptance predicates written directly from the endpoint contracts (the oracle; no shared code with the parsers). Where the predicate accepts, the test asserts the parsed result preserves the accepted strings verbatim (no coercion); where it rejects, it asserts the parser throws. The fixed examples stay as regression cases. identity-refresh.test.ts now 18/18 pass; tsc --noEmit clean.

@dezren39
dezren39 merged commit 52f7965 into main Nov 11, 2026
1 of 7 checks passed
@dezren39
dezren39 deleted the queue/14019-7839-identity-response-validation branch November 11, 2026 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant